var url = 'http://testwo.woyes.com/fqgClient/clientInterface';
var jsonMap = {platformId: "0757000002",
			channelId: "0757000002_100062",
			terminalId: "zhangwo",
			signMethod: "MD5",
			dataType: "json",
			reqtime: "1"};
var securityKey='5F2030CB850D95E5EE4193E56F3FBAA5';

var encryption = require('/encryption.js');
var util = require('/util.js')
var httputil = require('/httputil.js');

function getSign(obj){
  var tmp='';
  var tmpJson={};
  //排序
  Object.keys(obj).sort().forEach(function(k){tmpJson[k]=obj[k]});
  for(var item in tmpJson){ 
  		var jValue=tmpJson[item];//key所对应的value  
	    //console.log(item+":"+jValue);
	    tmp = tmp+item+"="+jValue+"&";
	}
  tmp = tmp+encryption.MD5(securityKey);
  return encryption.MD5(tmp);
}

function sendPost () {
	
	jsonMap.method="installmentsGoodsListByPage";
	jsonMap.pageNo="1";
	jsonMap.version="1";
	jsonMap.pageSize ="10";
	jsonMap.reqtime = util.formatDate(new Date(), 'yyyy-MM-dd/HH:mm:ss');
	var sign = getSign(jsonMap);
	console.log("hzh = "+sign);
	jsonMap.sign = sign;
console.log(jsonMap);
wx.request({
  url: url,
  data: jsonMap,
  method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  header: {'content-type': 'application/x-www-form-urlencoded'}, // 设置请求的 header
  success: function(res){
	// success
	   console.log(res);
  },
  fail: function() {
	// fail
  },
  complete: function() {
	// complete
  }
})

	// var strJson=JSON.stringify(jsonMap); //将JSON对象转化为JSON字符
	// console.log(strJson);
}

module.exports = {
    sendPost: sendPost
}